package com.atguigu.observer.improve;

/**
 * @program: design-patterns
 * @author: yangshen
 * @description:
 * @create: 2022-03-08 16:09
 **/
public class Client {
    public static void main(String[] args) {
        //创建一个WeatherData(天气数据的核心类)
        WeatherData weatherData = new WeatherData();

        //创建一个观察者
        CurrentConditions currentConditions = new CurrentConditions();
        //新加一个百度网站观察者
        BaiduSite baiduSite = new BaiduSite();

        //注册到weatherData
        weatherData.registerObserver(currentConditions);
        //将新加的百度网站注册
        weatherData.registerObserver(baiduSite);

        //测试
        System.out.println("通知各个注册的观察者，看看信息");
        weatherData.setData(10f, 100f, 30f);


        //测试,移除一个观察者
        System.out.println("-------------移除一个观察者(自己的网站)----------------------");
        weatherData.removeObserver(currentConditions);
        System.out.println("通知各个注册的观察者，看看信息");
        weatherData.setData(10f, 100f, 30f);
    }
}
